package com.beilang.hotline.sys.manager.impl;

import java.util.List;
import java.util.ArrayList;

import com.beilang.base.pagination.PaginationHelper;
import com.beilang.hotline.sys.dao.SysDAO;
import com.beilang.hotline.sys.manager.SysMgr;
import com.beilang.hotline.sys.model.SysModel;
import com.beilang.hotline.sys.to.SearchTO;
import com.beilang.hotline.module.manager.ModuleMgr;
import com.beilang.hotline.issue.manager.IssueMgr;
import com.beilang.hotline.knowledge.manager.KnowledgeMgr;

public class SysMgrImpl implements SysMgr{
	private SysDAO sysDAO;

    private ModuleMgr moduleMgr;

    private IssueMgr issueMgr;

    private KnowledgeMgr knowledgeMgr;

    public void setKnowledgeMgr(KnowledgeMgr knowledgeMgr) {
        this.knowledgeMgr = knowledgeMgr;
    }

    public void setModuleMgr(ModuleMgr moduleMgr) {
        this.moduleMgr = moduleMgr;
    }

    public void setIssueMgr(IssueMgr issueMgr) {
        this.issueMgr = issueMgr;
    }

    public void setSysDAO(SysDAO sysDAO) {
		this.sysDAO = sysDAO;
	}

	public SysModel createSys(SysModel sysModel){
		return sysDAO.createSys(sysModel);
	}

	public SysModel saveSys(SysModel sysModel){
		return sysDAO.saveSys(sysModel);
	}

	public void deleteSys(Long sysId){
		sysDAO.deleteSys(sysId);
        moduleMgr.deleteAllSysModules(sysId);
        issueMgr.deleteAllSysIssues(sysId);
        knowledgeMgr.deleteAllSysKnowledges(sysId);
    }

	public SysModel getSys(Long sysId){
		return sysDAO.getSys(sysId);
		
	}

	public PaginationHelper getSysList(PaginationHelper helper, SearchTO searchTO){
		int count = sysDAO.searchCount(searchTO);
		helper.setTotalSize(count);
		List list = sysDAO.searchList(helper, searchTO);
        if (list!=null&&!list.isEmpty())
        {
           for(int i=0;i<list.size();i++){
                SysModel s=(SysModel)list.get(i);
                if("N".equals(s.getCustomerViewInd()))
                {
                     s.setCustomerViewIndDesc("否");
                }else if("Y".equals(s.getCustomerViewInd()))
                {
                     s.setCustomerViewIndDesc("是");
                }
           }

        }

        helper.setList(list);
		return helper;
	}
	
	public List getAllSys(){
        List list= sysDAO.getAll(SysModel.class);
        if(list!=null&&list.size()>0){
            List l=new ArrayList();
            for(int i=0;i<list.size();i++){
                SysModel s=(SysModel)list.get(i);
                if("N".equals(s.getCustomerViewInd()))
                {
                     s.setCustomerViewIndDesc("否");
                }else if("Y".equals(s.getCustomerViewInd()))
                {
                     s.setCustomerViewIndDesc("是");
                }

                if(s.getDeleteInd().equalsIgnoreCase("N")){
                    l.add(s);
                }
            }
            return l;
        }
        return list;
    }

}
